package com.legal.aid.app.controller;

import com.legal.aid.app.domain.vo.ChatMessage;
import com.legal.aid.app.domain.vo.ChatListVO;
import com.legal.aid.app.service.ChatMessageService;
import com.legal.aid.common.core.controller.BaseController;
import com.legal.aid.common.core.domain.AjaxResult;
import com.legal.aid.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/chat")
public class AppChatController extends BaseController {

    @Autowired
    private ChatMessageService chatMessageService;

    @GetMapping("/history")
    public TableDataInfo getChatHistory(@RequestParam("userId") String userId,
            @RequestParam("lawyerId") String lawyerId,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("offset") Integer offset) {
        List<ChatMessage> chatHistory = chatMessageService.getChatHistory(userId, lawyerId, pageSize, offset);
        return getDataTable(chatHistory);
    }

    @GetMapping("/messageList/{userId}")
    public AjaxResult getMessageList(@PathVariable String userId) {
        List<ChatListVO> chatList = chatMessageService.getChatList(userId);
        return success(chatList);
    }

    @DeleteMapping("/delete/{messageId}")
    public AjaxResult deleteMessage(@PathVariable Long messageId) {
        chatMessageService.deleteMessage(messageId);
        return AjaxResult.success("删除成功");
    }

}
